import type { App } from 'vue'
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import Layout from '../layout/index.vue'
import { createRouterGuard } from './guard'
const routes: RouteRecordRaw[] = [
  {
    path: '/login',
    component: () => import(/* webpackChunkName: "dashboard" */ '../views/login/index.vue'),
    name: 'login',
    meta: { hidden: false , hasAuth: false}, // 头部图片隐藏
  },
  {
    path: '/',
    component: () => import(/* webpackChunkName: "dashboard" */ '../views/detail/index.vue'),
    name: 'detail',
    meta: { hidden: true , hasAuth: true},
  },
  {
    path: '/404',
    component: () => import(/* webpackChunkName: "dashboard" */ '../views/error/index.vue'),
    name: 'error',
    meta: {
      hidden: true,
      title: 'error',
      icon: '#icondashboard',
      affix: true,
      hasAuth: false
    },
  },
  {
    path: '/manage',
    component: Layout,
    meta: { hidden: true , hasAuth: true},
    children: [
    ],
  },
]

export const router = createRouter({
  history: createWebHistory(),
  routes,
})

export async function setupRouter(app: App) {
  app.use(router)
  createRouterGuard(router)
  await router.isReady()
}
